package com.car.loan.project.ve.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.car.loan.common.exception.loan.LoanParameterException;
import com.car.loan.project.ve.domain.VeVehicleAlbum;
import com.car.loan.project.ve.domain.VeVehicleEvaluation;
import com.car.loan.project.ve.mapper.VeVehicleAlbumMapper;
import com.car.loan.project.ve.mapper.VeVehicleEvaluationMapper;
import com.car.loan.project.ve.service.IVeVehicleAlbumService;
import com.car.loan.project.ve.util.enums.VehicleStatus;
import java.util.Collection;
import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

/**
 * 【请填写功能名称】Service业务层处理
 *
 * @author ruoyi
 * @date 2019-10-29
 */
@Service
public class VeVehicleAlbumServiceImpl implements IVeVehicleAlbumService {

    @Autowired
    private VeVehicleAlbumMapper veVehicleAlbumMapper;

    @Autowired
    private VeVehicleEvaluationMapper veVehicleEvaluationMapper;

    /**
     * 查询【请填写功能名称】
     *
     * @param id 【请填写功能名称】ID
     * @return 【请填写功能名称】
     */
    @Override
    public VeVehicleAlbum selectVeVehicleAlbumById(Long id) {
        return veVehicleAlbumMapper.selectById(id);
    }

    /**
     * 查询【请填写功能名称】列表
     *
     * @param veVehicleAlbum 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<VeVehicleAlbum> selectVeVehicleAlbumList(VeVehicleAlbum veVehicleAlbum) {
        QueryWrapper<VeVehicleAlbum> queryWrapper = new QueryWrapper<>(veVehicleAlbum);
        return veVehicleAlbumMapper.selectList(queryWrapper);
    }


    @Override
    public IPage<VeVehicleAlbum> selectPage(IPage<VeVehicleAlbum> page,
        QueryWrapper<VeVehicleAlbum> queryWrapper) {
        return veVehicleAlbumMapper.selectPage(page, queryWrapper);
    }

    /**
     * 新增【请填写功能名称】
     *
     * @param veVehicleAlbum 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertVeVehicleAlbum(VeVehicleAlbum veVehicleAlbum) {

        return veVehicleAlbumMapper.insert(veVehicleAlbum);
    }

    /**
     * 修改【请填写功能名称】
     *
     * @param veVehicleAlbum 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateVeVehicleAlbum(VeVehicleAlbum veVehicleAlbum) {

        return veVehicleAlbumMapper.updateById(veVehicleAlbum);
    }

    /**
     * 删除【请填写功能名称】对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteVeVehicleAlbumByIds(Collection<Long> ids) {
        return veVehicleAlbumMapper.deleteBatchIds(ids);
    }

    /**
     * 删除【请填写功能名称】信息
     *
     * @param id 【请填写功能名称】ID
     * @return 结果
     */
    @Override
    public int deleteVeVehicleAlbumById(Long id) {
        VeVehicleAlbum veVehicleAlbum = veVehicleAlbumMapper.selectById(id);
        if (null == veVehicleAlbum) {
            return 1;
        }
        VeVehicleEvaluation veVehicleEvaluation = veVehicleEvaluationMapper
            .selectById(veVehicleAlbum.getVehicleId());
        if (VehicleStatus.INIT.status == veVehicleEvaluation.getStatus()
            || VehicleStatus.REVOKE.status == veVehicleEvaluation.getStatus()) {
            return veVehicleAlbumMapper.deleteById(id);
        }
        throw new LoanParameterException("当前状态不可删除");
    }
}
